package com.qijian.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qijian.system.domain.Dept;
import com.qijian.system.domain.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface DeptMapper extends BaseMapper<Dept> {


    @Select("select a.* from sys_dept a inner join(" +
            " SELECT  IFNULL(directDept.deptId, parentDept.deptId)  dept_id"+
    " from  sys_dept sd"+
    " left join (select 126027 as deptId,'总调车间' as deptName union"+
     "       select 126017 as deptId,'质检部' as deptName union"+
      "                 select 126028 as deptId,'数控车间' as deptName union"+
       "                select 126029 as deptId,'金工车间' as deptName union"+
        "               select 126030 as deptId,'结构一组' as deptName union"+
         "              select 126031 as deptId,'结构二组' as deptName union"+
          "             select 126032 as deptId,'结构三组' as deptName union"+
           "            select 126033 as deptId,'结构四组' as deptName union"+
            "           select 231974 as deptId,'装配事业部' as deptName union"+
             "          select 126034 as deptId,'油漆车间' as deptName union"+
              "         select 617768 as deptId ,'油漆车间-流水线'as deptName"+
   " ) directDept on sd.dept_id  = directDept.deptId"+
   " left join"+
    "        ("+
     "               select 126027 as deptId,'总调车间' as deptName union "+
      "              select 126017 as deptId,'质检部' as deptName union "+
       "                     select 126028 as deptId,'数控车间' as deptName union"+
        "                    select 126029 as deptId,'金工车间' as deptName union"+
         "                   select 126030 as deptId,'结构一组' as deptName union"+
          "                  select 126031 as deptId,'结构二组' as deptName union"+
           "                 select 126032 as deptId,'结构三组' as deptName union"+
            "                select 126033 as deptId,'结构四组' as deptName union"+
             "               select 231974 as deptId,'装配事业部' as deptName union"+
              "              select 126034 as deptId,'油漆车间' as deptName union"+
               "             select 617768 as deptId ,'油漆车间-流水线'as deptName"+
            " ) parentDept on FIND_IN_SET(parentDept.deptId,sd.ancestors)"+
    " where sd.dept_id = #{dept_id}) b on a.dept_id = b.dept_id  "
            + "  inner join sys_user c on c.user_id = a.leader_id and c.status = 0 ")
    Dept getDeptLeader(@Param("dept_id") Long deptId);
}
